<template>
  <div class="app-container">
    <div v-if="!open">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="80px">
        <el-form-item label="所属小区" prop="estateId">
          <el-select v-model="queryParams.estateId" placeholder="请选择小区" style="width:140px;" size="mini" filterable clearable>
            <el-option v-for="estate in estatesOptions"
                       :key="estate.id"
                       :label="estate.estateName"
                       :value="estate.id"/>
          </el-select>
        </el-form-item>
<!--        <el-form-item label="支付平台" prop="payPlatform">-->
<!--          <el-select v-model="queryParams.payPlatform" placeholder="请选择支付平台" size="mini" clearable>-->
<!--            <el-option :value="0" label="微信支付"/>-->
<!--            <el-option :value="1" label="农商银联支付"/>-->
<!--            <el-option :value="2" label="线下支付"/>-->
<!--            <el-option :value="3" label="现金支付"/>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
        <el-form-item label="订单状态" prop="state">
          <el-select v-model="queryParams.state" placeholder="选择订单状态" style="width:140px;" size="mini" clearable>
            <!-- 0 - 交费申请 1 - 已生成交费清单    2 - 未支付  3- 支付中 4 - 已支付 5 - 订单取消-->
            <el-option label="待处理" :value="0" />
            <el-option label="已生成交费清单" :value="1" />
            <el-option label="待支付" :value="2" />
            <el-option label="支付中" :value="3" />
            <el-option label="已支付" :value="4" />
            <el-option label="订单取消" :value="5" />
          </el-select>
        </el-form-item>
        <el-form-item label="关键字" prop="orderNo">
          <el-input v-model="queryParams.orderNo" placeholder="手机号或订单号" clearable size="mini"
            @keyup.enter.native="handleQuery" style="width:140px;"/>
        </el-form-item>
        <el-form-item label="查询时间">
          <el-date-picker v-model="dateRange" size="mini" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
                          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
        <el-tab-pane label="线下现金" name="2"/>
        <el-tab-pane label="微信扫码" name="3"/>
        <el-tab-pane label="银行转账" name="4"/>
        <el-tab-pane label="支付宝收款" name="5"/>
        <el-tab-pane label="预存抵扣" name="6"/>
        <el-tab-pane label="转账支付" name="7"/>
        <el-tab-pane label="多种付款" name="8"/>
        <el-tab-pane label="线上支付" name="1"/>
        <el-tab-pane label="押金支付" name="10"/>
        <el-tab-pane label="全部订单" name="9"/>
      </el-tabs>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" icon="el-icon-edit" size="mini" @click="handleAdd"
                     v-hasPermi="['module:propertyorder:add']">新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="success" icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
                     v-hasPermi="['module:propertyorder:edit']">修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="warning" icon="el-icon-download" size="mini" :loading="exportLoading" @click="handleExport"
                     v-hasPermi="['module:propertyorder:export']">导出</el-button>
        </el-col>

        <el-col :span="1.5">
          <el-button type="danger" icon="el-icon-delete" size="mini" @click="selectDelete(1)" v-if="this.queryParams.isDel==0">查看作废</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="success" icon="el-icon-edit" size="mini" @click="selectDelete(0)" v-if="this.queryParams.isDel==1">查看交费</el-button>
        </el-col>

        <el-col :span="1.5">
          <el-button type="danger" icon="el-icon-delete" size="mini" @click="selectYajinDelete(7)" v-if="this.queryParams.state==4">押金退费</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="success" icon="el-icon-edit" size="mini" @click="selectYajinDelete(4)" v-if="this.queryParams.state==7">查看交费</el-button>
        </el-col>

        <el-col :span="1.5">
          <el-tag style="cursor: pointer" :type="'success'">{{'总需交费：' + totalFee.totalMoney +'元'}}</el-tag>
        </el-col>
        <el-col :span="1.5">
          <el-tag style="cursor: pointer" :type="'success'">{{'当前共收费：' + totalFee.payMoney +'元'}}</el-tag>
        </el-col>
        <el-col :span="1.5">
          <el-tag style="cursor: pointer" :type="'danger'">{{'物业费：' + totalFee.wyfFee +'元'}}</el-tag>
        </el-col>
        <el-col :span="1.5">
          <el-tag style="cursor: pointer" :type="''">{{'水费：' + totalFee.waterFee +'元'}}</el-tag>
        </el-col>
        <el-col :span="1.5">
          <el-tag style="cursor: pointer" :type="'warning'">{{'电费：' + totalFee.electricFee +'元'}}</el-tag>
        </el-col>
        <el-col :span="1.5">
          <el-tag style="cursor: pointer" :type="'info'">{{'垃圾处理费：' + totalFee.trashFee +'元'}}</el-tag>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" stripe :data="orderList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="45" align="center" />

        <el-table-column label="所属小区" align="center" prop="estateName" width="150"/>
        <el-table-column label="所属物业" align="center" prop="propertyName" width="120"/>
        <el-table-column label="户号" align="center" prop="roomNo" width="120"/>
        <el-table-column label="业主手机号" align="center" prop="phoneNum" width="120"/>
        <el-table-column label="业主昵称" align="center" prop="nickName" width="170">
          <template slot-scope="scope">
            <span>{{(scope.row.realName!=null ? scope.row.realName:'') + ' ' + '('+ scope.row.nickName +')'  }}</span>
          </template>
        </el-table-column>
        <el-table-column label="支付平台" align="center" prop="payPlatform" width="110">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.payPlatform === 0" style="cursor: pointer" :type="''">微信支付</el-tag>
            <el-tag v-if="scope.row.payPlatform === 1" style="cursor: pointer" :type="''">银联微信</el-tag>
            <el-tag v-if="scope.row.payPlatform === 2" style="cursor: pointer" :type="''">现金支付</el-tag>
            <el-tag v-if="scope.row.payPlatform === 3" style="cursor: pointer" :type="''">微信支付</el-tag>
            <el-tag v-if="scope.row.payPlatform === 4" style="cursor: pointer" :type="''">刷卡支付</el-tag>
            <el-tag v-if="scope.row.payPlatform === 5" style="cursor: pointer" :type="''">支付宝支付</el-tag>
            <el-tag v-if="scope.row.payPlatform === 6" style="cursor: pointer" :type="''">预存抵扣</el-tag>
            <el-tag v-if="scope.row.payPlatform === 7" style="cursor: pointer" :type="''">转账支付</el-tag>
            <el-tag v-if="scope.row.payPlatform === 8" style="cursor: pointer" :type="''">多种付款</el-tag>
            <el-tag v-if="scope.row.payPlatform === 10" style="cursor: pointer" :type="''">押金支付</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="物业费" align="center" prop="wyfFee" width="100">
          <template slot-scope="scope">
            <span>{{ (scope.row.wyfFee!=null?scope.row.wyfFee:'0.00') +'元' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="垃圾处理费" align="center" prop="trashFee" width="100">
          <template slot-scope="scope">
            <span>{{(scope.row.trashFee!=null?scope.row.trashFee:'0.00') +'元' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="代收水费" align="center" prop="waterFee" >
          <template slot-scope="scope">
            <span>{{ (scope.row.waterFee!=null?scope.row.waterFee:'0.00') +'元' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="加压费" align="center" prop="jiaYaFee">
          <template slot-scope="scope">
            <span>{{ (scope.row.jiaYaFee!=null?scope.row.jiaYaFee:'0.00') +'元' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="代收电费" align="center" prop="electricFee">
          <template slot-scope="scope">
            <span>{{ (scope.row.electricFee!=null?scope.row.electricFee:'0.00') +'元' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="车位费" align="center" prop="carFee">
          <template slot-scope="scope">
            <span>{{ (scope.row.carFee!=null?scope.row.carFee:'0.00') +'元' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="需支付金额" align="center" prop="totalMoney" width="100">
          <template slot-scope="scope">
            <span>{{ (scope.row.totalMoney!=null?scope.row.totalMoney:'0.00') +'元' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="物业费优惠金额" align="center" prop="wyfYhPrice" width="150">
          <template slot-scope="scope">
            <span>{{ (scope.row.wyfYhPrice!=null ? scope.row.wyfYhPrice+'元('+scope.row.wyfYhRate+'折)' : '0.00元')}}</span>
          </template>
        </el-table-column>
        <el-table-column label="下单时间" align="center" prop="createTime" width="170"/>
        <el-table-column label="支付时间" align="center" prop="payTime" width="170" />
        <el-table-column label="收据" align="center" prop="receiptImgUrl" width="150" >
          <template slot-scope="scope">
<!--            <div>{{scope.row.receiptImgUrl}}</div>-->
            <el-popover v-if="scope.row.receiptImgUrl!=null" placement="right" width="700" trigger="hover">
              <el-image style="width: 680px; height: 600px" :src="scope.row.receiptImgUrlPath"  fit="fill" />
<!--              <i class="el-icon-picture" slot="reference"/>-->
              <el-tag style="cursor: pointer" :type="''" slot="reference">已生成收据</el-tag>
            </el-popover>
<!--            <el-tag v-if="scope.row.receiptImgUrl!=null" style="cursor: pointer" :type="''">已生成收据</el-tag>-->
            <el-tag v-else style="cursor: pointer" :type="'warning'">未生成收据</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="订单号" align="center" prop="orderNo" width="200"/>
        <el-table-column label="支付流水号" align="center" prop="outTradeNo" width="200"/>

        <el-table-column label="订单状态" align="center" prop="state" fixed="right" width="95" >
          <template slot-scope="scope">
            <div>
  <!--            订单状态   0 - 交费申请 1 - 已生成交费清单 2 - 待支付  3- 支付中  4 - 已支付 5 - 订单取消-->
              <el-tag v-if="scope.row.state === 0" style="cursor: pointer" :type="'warning'">待处理</el-tag>
              <el-tag v-if="scope.row.state === 1" style="cursor: pointer" :type="''">已生成清单</el-tag>
              <el-tag v-if="scope.row.state === 2" style="cursor: pointer" :type="''">待支付</el-tag>
              <el-tag v-if="scope.row.state === 3" style="cursor: pointer" :type="''">支付中</el-tag>
              <el-tag v-if="scope.row.state === 4" style="cursor: pointer" :type="'success'">已支付</el-tag>
              <el-tag v-if="scope.row.state === 5" style="cursor: pointer" :type="'danger'">订单取消</el-tag>
              <el-tag v-if="scope.row.state === 6" style="cursor: pointer" :type="'warning'">已发起退款</el-tag>
              <el-tag v-if="scope.row.state === 7" style="cursor: pointer" :type="'success'">退款成功</el-tag>
              <el-tag v-if="scope.row.state === 8" style="cursor: pointer" :type="'danger'">退款失败</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="支付金额" align="center" prop="payMoney" width="110" fixed="right" >
          <template slot-scope="scope">
            <span>{{ (scope.row.payMoney!=null?scope.row.payMoney:'0.00') +'元' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" :key="Math.random()" align="center" class-name="small-padding fixed-width" fixed="right" width="250">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" v-if="scope.row.state!=7"
                       @click="handleUpdateTime(scope.row)" v-hasPermi="['module:chargerorder:edit']">修改</el-button>
            <el-button size="mini" type="text" icon="el-icon-edit" v-if="userId === 1&&scope.row.payPlatform === 1"
                       @click="handleRefund(scope.row)" v-hasPermi="['module:chargerorder:edit']">退款</el-button>
            <el-button size="mini" type="text" v-if="scope.row.state < 3"  icon="el-icon-edit" @click="handleUpdate(scope.row)"
                       v-hasPermi="['module:propertyorder:edit']">订单处理</el-button>
            <el-button size="mini" type="text" v-if="scope.row.state === 3 || scope.row.state === 5"  icon="el-icon-edit" @click="handleOrderPayStatusQuery(scope.row)"
                       v-hasPermi="['module:propertyorder:edit']">支付查询</el-button>
            <el-button size="mini" type="text" v-if="scope.row.state === 4 "  icon="el-icon-edit" @click="downloadSettle(scope.row)">下载收据</el-button>
            <el-button size="mini" type="text" icon="el-icon-s-order"  @click="handleUpdate(scope.row)">详情</el-button>
<!--            <el-button size="mini" type="text" icon="el-icon-delete"  v-if="scope.row.state!==4" @click="handleDelete(scope.row)"-->
<!--                       v-hasPermi="['module:propertyorder:remove']">删除</el-button>-->
            <el-button size="mini" type="text" icon="el-icon-delete"  v-if="scope.row.state===4 && queryParams.payPlatform===2 || queryParams.payPlatform == 3|| queryParams.payPlatform == 4|| queryParams.payPlatform == 5 || queryParams.payPlatform===6 ||queryParams.payPlatform===7 ||queryParams.payPlatform===8"
                       @click="handleVoid(scope.row)"
                       v-hasPermi="['module:propertyorder:void']">作废</el-button>
            <el-button size="mini" type="text" icon="el-icon-delete"  v-if="queryParams.payPlatform===10&&scope.row.state!=7"
                       @click="handleVoid(scope.row)"
                       v-hasPermi="['module:propertyorder:void']">退款</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0"
                  :total="total"
                  :page.sync="queryParams.pageNum"
                  :limit.sync="queryParams.pageSize"
                  @pagination="getList" />
    </div>

    <el-dialog :title="title" :visible.sync="openTime" width="550px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="缴费方式" prop="rechargeWay">
          <el-select v-model="form.payPlatform" placeholder="请选择缴费方式" filterable clearable
                     size="mini">
            <el-option label="现金缴费" :value="2"/>
            <el-option label="微信缴费" :value="3"/>
            <el-option label="刷卡缴费" :value="4"/>
            <el-option label="支付宝缴费" :value="5"/>
            <el-option label="预存抵扣" :value="6"/>
            <el-option label="转账支付" :value="7"/>
            <el-option label="多种付款" :value="8"/>
          </el-select>
        </el-form-item>
        <el-form-item label="缴费时间" prop="createTime">
          <el-date-picker clearable size="mini" v-model="form.createTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="选择缴费时间时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" size="mini" type="primary" @click="submitFormTime">确 定</el-button>
        <el-button @click="cancel" size="mini">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改物业费订单对话框 -->
    <div v-if="open">
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-row>
          <el-col :span="15">
            <el-col :span="12">
              <el-form-item label="所属小区" prop="estateId">
                <el-select v-model="form.estateId" placeholder="请选择小区" :disabled="form.state === 4" size="mini" @change="selectEstate" filterable clearable>
                  <el-option value="">请选择小区</el-option>
                  <el-option v-for="(estate) in estatesOptions"
                             :key="estate"
                             :label="estate.estateName"
                             :value="estate.id"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="楼房房间号" prop="roomNo">
                <el-input v-model="form.roomNo" placeholder="请输入楼房房间号" :disabled="form.state === 4" size="mini"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="业主手机号" prop="phoneNum">
                <el-input v-model="form.phoneNum" placeholder="请输入业主手机号" :disabled="form.state === 4" size="mini" @blur="getWxUserList">
                  <template slot="append">
                    <el-button icon="el-icon-search" @click="getWxUserList" circle/>
                  </template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="业主微信" prop="userId">
                <el-select v-model="form.userId" :disabled="form.state === 4" placeholder="请选择业主微信" size="mini" >
                  <el-option v-for="wxUser in wxUserOptions"
                    :key="wxUser.id"
                    :label="wxUser.nickName"
                    :value="wxUser.id"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="房屋类型" props="roomType">
                <el-radio-group v-model="form.roomType" :disabled="form.state === 4" @change="selectRoomType">
                  <el-radio :value="0" :label="0">高层</el-radio>
                  <el-radio :value="1" :label="1">多层</el-radio>
                  <el-radio :value="2" :label="2">商业</el-radio>
                  <el-radio :value="3" :label="3">别墅</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="房屋面积" prop="roomAreas">
                <el-input type="number" v-model="form.roomAreas" placeholder="请输入房屋面积" :disabled="form.state === 4" size="mini" @blur="getWyfFee">
                  <template slot="append">平</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12" v-if="form.wyfFee > 0">
              <el-form-item label="物业费" prop="wyfFee" >
                <el-input type="number" v-model="form.wyfFee" placeholder="请输入物业费"  :disabled="form.state === 4" size="mini" @blur="getAllPrice">
                  <template slot="append" style="width:180px;">元</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12" v-if="form.wyfYhPrice > 0">
              <el-form-item label="物业费" prop="wyfYhPrice" >
                <el-input type="number" v-model="form.wyfYhPrice" placeholder="请输入物业费"  :disabled="form.state === 4" size="mini" @blur="getAllPrice">
                  <template slot="append" style="width:180px;">元</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12"  v-if="form.trashFee > 0">
              <el-form-item label="垃圾处理费" prop="trashFee">
                <el-input type="number" v-model="form.trashFee" placeholder="请输入物业费" :disabled="form.state === 4" size="mini" @blur="getAllPrice">
                  <template slot="append" style="width:180px;">元</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12"  v-if="form.trashYouhui > 0">
              <el-form-item label="垃圾处理优惠" prop="trashYouhui">
                <el-input type="number" v-model="form.trashYouhui" placeholder="请输入物业费" :disabled="form.state === 4" size="mini" @blur="getAllPrice">
                  <template slot="append" style="width:180px;">元</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12" v-if="form.carFee > 0">
              <el-form-item label="车位费" prop="carFee" >
                <el-input type="number" v-model="form.carFee" placeholder="请输入车位费" :disabled="form.state === 4" size="mini" @blur="getAllPrice">
                  <template slot="append"><span style="width:180px;">{{'元'}}</span></template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12" v-if="form.carYouhui > 0">
              <el-form-item label="车位优惠" prop="carYouhui" >
                <el-input type="number" v-model="form.carYouhui" placeholder="请输入车位优惠" :disabled="form.state === 4" size="mini" @blur="getAllPrice">
                  <template slot="append"><span style="width:180px;">{{'元'}}</span></template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12" v-if="form.waterFee > 0">
              <el-form-item label="代收水费" prop="waterFee"  >
                <el-input type="number" v-model="form.waterFee" placeholder="请输入物业费" :disabled="form.state === 4" size="mini" @blur="getAllPrice">
                  <template slot="append" style="width:180px;">元</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12" v-if="form.jiaYaFee > 0">
              <el-form-item label="加压费" prop="jiaYaFee"  >
                <el-input type="number" v-model="form.jiaYaFee" placeholder="请输入加压费" :disabled="form.state === 4" size="mini" @blur="getAllPrice">
                  <template slot="append">元</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12" v-if="form.jiaYaYouhui > 0">
              <el-form-item label="加压优惠" prop="jiaYaYouhui"  >
                <el-input type="number" v-model="form.jiaYaYouhui" placeholder="请输入加压优惠" :disabled="form.state === 4" size="mini" @blur="getAllPrice">
                  <template slot="append">元</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12" v-if="form.electricFee > 0">
              <el-form-item label="代收电费" prop="electricFee" >
                <el-input type="number" v-model="form.electricFee" placeholder="请输入物业费" :disabled="form.state === 4" size="mini" @blur="getAllPrice">
                  <template slot="append">元</template>
                </el-input>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="备注信息" prop="remark">
                <el-input v-model="form.remark" type="textarea" placeholder="请输入备注信息" size="mini"/>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <div style="text-align: center;">
                <el-button :loading="buttonLoading" size="mini" type="primary" @click="submitForm(0)">保存</el-button>
<!--                <el-button :loading="buttonLoading" size="mini" type="warning" @click="submitForm(1)">保存并提交</el-button>-->
<!--                <el-button :loading="buttonLoading" size="mini" type="success" @click="sendWxMessage(form.id)">单独发送微信推送消息</el-button>-->
                <el-button @click="cancel" size="mini">取 消</el-button>
                <a v-if="form.receiptImgUrlPath!=null" :href="form.receiptImgUrlPath" style="color: #42b983;margin-left: 20px;" target="_blank">
                  <el-button size="mini" type="success">收 据</el-button>
                </a>
              </div>
            </el-col>
          </el-col>
          <el-col :span="6">
<!--            <el-image style="width: 400px; height: 400px" :src="form.receiptImgUrlPath"  fit="fill" />-->
          </el-col>
        </el-row>
        <el-row style="margin-top: 10px;">
          <el-col :span="24">
            <span>交费项统计</span>
            <el-table stripe :data="form.orderInfoList">
              <el-table-column label="费用类型" align="center" prop="feeType" width="100">
                <!--        wyf - 物业费 rubbish - 垃圾处理费 car - 车位费  water - 水费 ，eletrict - 电费 ，jiaya - 加压费-->
                <template slot-scope="scope">
                  <div>
                    <el-tag v-if="scope.row.feeType === 'wyf'" style="cursor: pointer" :type="''">物业费</el-tag>
                    <el-tag v-if="scope.row.feeType === 'rubbish'" style="cursor: pointer" :type="'success'">垃圾处理费</el-tag>
                    <el-tag v-if="scope.row.feeType === 'car'" style="cursor: pointer" :type="'warning'">车位费</el-tag>
                    <el-tag v-if="scope.row.feeType === 'water'" style="cursor: pointer" :type="'success'">水费</el-tag>
                    <el-tag v-if="scope.row.feeType === 'jiaya'" style="cursor: pointer" :type="''">加压费</el-tag>
                    <el-tag v-if="scope.row.feeType === 'eletrict'" style="cursor: pointer" :type="'warning'">电费</el-tag>
                    <el-tag v-if="scope.row.feeType === 'account'" style="cursor: pointer" :type="'warning'">套内账户</el-tag>
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="交费区间" align="center" prop="beginMonth" width="200">
                <template slot-scope="scope" v-if="scope.row.beginMonth!=undefined">
                  {{ scope.row.beginMonth +' ~ ' +  scope.row.endMonth }}
                </template>
                <template slot-scope="scope" v-if="scope.row.beginMonth==null">
                  {{ "无区间限制" }}
                </template>
              </el-table-column>
              <el-table-column label="总金额" align="center" prop="totalPrice">
                <template slot-scope="scope">
                  <div>{{  (scope.row.totalPrice != null ? scope.row.totalPrice : 0.00) + '元'}}</div>
                </template>
              </el-table-column>
              <el-table-column label="支付金额" align="center" prop="payPrice">
                <template slot-scope="scope">
                  <div>{{  (scope.row.payPrice != null ? scope.row.payPrice : 0.00) + '元'}}</div>
                </template>
              </el-table-column>
              <el-table-column label="数量"  align="center" prop="paidCount" width="250">
                <template slot-scope="scope">
                  <div v-if="scope.row.feeType === 'car'">{{ scope.row.paidCount + '个' }}</div>
                  <div v-else-if="scope.row.feeType === 'water'">
                    {{ '起：' + scope.row.beginCount +'，止：' + scope.row.endCount + ',共'+scope.row.paidCount+'³' }}
                  </div>
                  <div v-else>{{ scope.row.paidCount }}</div>
                </template>
              </el-table-column>
              <el-table-column label="优惠金额" align="center" prop="youhuiPrice">
                <template slot-scope="scope">
                  <div>{{ (scope.row.youhuiPrice != null ? scope.row.youhuiPrice : 0.00) + '元'}}</div>
                </template>
              </el-table-column>
              <el-table-column label="备注信息" align="center" prop="remark" />
            </el-table>
          </el-col>
          <el-col>
            <span>交费详情</span>
            <el-table stripe :data="form.templates">
              <el-table-column label="费用类型" align="center" prop="feeType" width="100">
                <!--        wyf - 物业费 rubbish - 垃圾处理费 car - 车位费  water - 水费 ，eletrict - 电费 ，jiaya - 加压费-->
                <template slot-scope="scope">
                  <div>
                    <el-tag v-if="scope.row.feeType === 'wyf'" style="cursor: pointer" :type="''">物业费</el-tag>
                    <el-tag v-if="scope.row.feeType === 'rubbish'" style="cursor: pointer" :type="'success'">垃圾处理费</el-tag>
                    <el-tag v-if="scope.row.feeType === 'car'" style="cursor: pointer" :type="'warning'">车位费</el-tag>
                    <el-tag v-if="scope.row.feeType === 'water'" style="cursor: pointer" :type="'success'">水费</el-tag>
                    <el-tag v-if="scope.row.feeType === 'jiaya'" style="cursor: pointer" :type="''">加压费</el-tag>
                    <el-tag v-if="scope.row.feeType === 'eletrict'" style="cursor: pointer" :type="'warning'">电费</el-tag>
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="费用时间" align="center" prop="yearNum" width="120">
                <template slot-scope="scope">
                  {{ scope.row.yearNum +' 年' +  scope.row.monthNum +' 月' }}
                </template>
              </el-table-column>
              <el-table-column label="总金额" align="center" prop="singlePrice">
                <template slot-scope="scope">
                  <div>{{  (scope.row.totalPrice != null ? scope.row.totalPrice : 0.00) + '元'}}</div>
                </template>
              </el-table-column>
              <el-table-column label="单价" align="center" prop="singlePrice">
                <template slot-scope="scope">
                  <div>{{  (scope.row.singlePrice != null ? scope.row.singlePrice : 0.00) + '元'}}</div>
                </template>
              </el-table-column>
              <el-table-column label="数量"  align="center" prop="paidCount" width="250">
                <template slot-scope="scope">
                  <div v-if="scope.row.feeType === 'car'">{{ scope.row.paidCount + '个' }}</div>
                  <div v-else-if="scope.row.feeType === 'water'">
                    {{ '起：' + scope.row.beginCount +'，止：' + scope.row.endCount + ',共'+scope.row.paidCount+'³' }}
                  </div>
                  <div v-else>{{ scope.row.paidCount }}</div>
                </template>
              </el-table-column>
              <el-table-column label="优惠金额" align="center" prop="youhuiPrice">
                <template slot-scope="scope">
                  <div>{{ (scope.row.youhuiPrice != null ? scope.row.youhuiPrice : 0.00) + '元'}}</div>
                </template>
              </el-table-column>
              <el-table-column label="备注信息" align="center" prop="remark" />
            </el-table>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
import {
  listOrder,
  getOrder,
  delOrder,
  addOrder,
  updateOrder,
  exportOrder,
  sendWxMessage,
  queryOrder,
  refundOrder,
  voidOrder, updateOrderTime
} from "@/api/module/property/order";
  import { listByPhone } from "@/api/module/wx/user";

  import { listAllEstate } from "@/api/module/estate/estate";
  import Template from "../wx/template";
import {getBanner} from "@/api/module/banner";


  export default {
    name: "Order",
    components: {Template},
    data() {
      return {
        activeName:"2",
        // 按钮loading
        buttonLoading: false,
        // 遮罩层
        loading: true,
        loadingSearchUser: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        dateRange:[],
        // 总条数
        total: 0,
        userId:0,
        openTime:false,
        // 物业费订单表格数据
        orderList: [],
        estatesOptions: [],
        wxUserOptions:[],
        estate:{
          wyfHighSinglePrice:0,
          wyfLowSinglePrice:0,
          wyfBusinessPrice:0,
          wyfVillaSinglePrice:0,
          waterSinglePrice:0,
          trashSinglePrice:0,
          electricSinglePrice:0,
        },
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          state:4,
          estateId: undefined,
          orderNo: undefined,
          payPlatform:2,
          beginDate:undefined,
          endDate:undefined,
          isDel:0,
        },
        queryParamsWxUser: {
          estateId: undefined,
          phoneNum: undefined,
        },
        months:0,
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          estateId: [
            { required: true, message: "请选择所属小区", trigger: "blur" }
          ],
          phoneNum: [
            { required: true, message: "手机号不能为空", trigger: "blur" }
          ],
          roomType :[
            { required: true, message: "房屋类型不能为空", trigger: "blur" }
          ],
          roomAreas :[
            { required: true, message: "房屋面积不能为空", trigger: "blur" }
          ],
          roomNo :[
            { required: true, message: "楼房房间号不能为空", trigger: "blur" }
          ],
          dateRange:[
            { required: true, message: "缴费时间不能为空", trigger: "blur" }
          ],
          userId:[
            { required: true, message: "请选择业主微信", trigger: "blur" }
          ],
        },
        totalFee:undefined,
      };
    },
    created() {
      this.getList();
      this.getEstateList()
    },
    methods: {
      /** 查询物业费订单列表 */
      getList() {
        this.loading = true;
        listOrder(this.queryParams).then(response => {
          this.orderList = response.rows;
          this.totalFee = response.otherData.feeOrder;
          this.userId = response.otherData.userId;
          this.total = response.total;
          this.loading = false;
        });
      },
      handleUpdateTime(row){
        this.loading = true;
        this.reset();
        this.openTime = true;
        const id = row.id || this.ids;
        getOrder(id).then(response => {
          this.loading = false;
          this.form = response.data;
          this.title = "修改订单信息";
        });
      },
      handleClick(val){
        console.log('handleClick',val.name);
        this.activeName = val.name;
        if(val.name!="9"){
          this.queryParams.payPlatform = parseInt(val.name);
        }else {
          this.queryParams.payPlatform = undefined;
        }
        this.getList();
      },
      getWxUserList() {
        this.queryParamsWxUser.phoneNum = this.form.phoneNum;
        this.loadingSearchUser = true;
        listByPhone(this.queryParamsWxUser).then(response => {
          this.wxUserOptions = response.data;
          this.loadingSearchUser = false;
        });
      },
      getEstateList() {
        listAllEstate().then(response => {
          this.estatesOptions = response.data;
        });
      },
      selectEstate(val){
        console.log('selectEstate',val);
        for(var index in this.estatesOptions) {
          if(this.estatesOptions[index].id === val){
            this.estate = this.estatesOptions[index];
          }
        }
        // this.estate = val;
        // this.form.estateId = val.id;
        this.queryParamsWxUser.estateId = val;
        if(this.form.roomType === 0){
          this.form.wyfSinglePrice = this.estate.wyfHighSinglePrice;
        } else if(this.form.roomType === 1){
          this.form.wyfSinglePrice = this.estate.wyfLowSinglePrice;
        } else if(this.form.roomType === 2){
          this.form.wyfSinglePrice = this.estate.wyfBusinessPrice;
        } else if(this.form.roomType === 3){
          this.form.wyfSinglePrice = this.estate.wyfVillaSinglePrice;
        }
        this.getWyfFee()
      },
      chooseImg(data){
        console.log("productfeeorder chooseImg",data);
        this.form.receiptImgUrl = "";
        this.form.receiptImgUrlPath = "";
        var imgUrlArray = data.imgUrl;
        // var imgUrlArrayPath = data.imgUrl;
        for(var index in imgUrlArray){
          var fileName = imgUrlArray[index].name.replace("https://www.caihengyun.com/chyimg/","");
          this.form.receiptImgUrl += fileName + ",";
          this.form.receiptImgUrlPath += imgUrlArray[index].url + ",";
        }
        this.form.receiptImgUrl = this.form.receiptImgUrl.substring(0,this.form.receiptImgUrl.length - 1);
        this.form.receiptImgUrlPath = this.form.receiptImgUrlPath.substring(0,this.form.receiptImgUrlPath.length - 1);
      },
      removeImg(data){
        console.log('removeImg',data);
        this.form.sliderImage = data.imgUrl;
      },
      selectRoomType(val){
        console.log('selectRoomType',val);
      // <el-radio :value="0" :label="0">高层 {{estate.wyfHighSinglePrice}} 元 / 平</el-radio>
      //   <el-radio :value="1" :label="1">多层 {{estate.wyfLowSinglePrice}} 元 / 平</el-radio><br/>
      //   <el-radio :value="2" :label="2">商业 {{estate.wyfBusinessPrice}} 元 / 平</el-radio>
      //   <el-radio :value="3" :label="3">别墅 {{estate.wyfVillaSinglePrice}} 元 / 平</el-radio>
        if(val === 0){
          this.form.wyfSinglePrice = this.estate.wyfHighSinglePrice;
        } else if(val === 1){
          this.form.wyfSinglePrice = this.estate.wyfLowSinglePrice;
        } else if(val === 2){
          this.form.wyfSinglePrice = this.estate.wyfBusinessPrice;
        } else if(val === 3){
          this.form.wyfSinglePrice = this.estate.wyfVillaSinglePrice;
        }
      },
      getWyfFee(){
        console.log('this.estate.id',this.estate.id);
        console.log('this.form.estateId',this.form.estateId);
        console.log('this.form.roomAreas',this.form.roomAreas);
        if(this.form.months > 0 && this.estate.id !== undefined && this.form.roomType!== undefined && this.form.estateId !== undefined && this.form.roomAreas !== undefined){
          this.form.wyfFee = this.form.roomAreas * this.form.wyfSinglePrice * this.form.months;
          this.form.wyfFee = Math.round(this.form.wyfFee*100)/100
        }
        console.log('this.form.months',this.form.months);
        console.log('this.form.peopleCount',this.form.peopleCount);
        console.log('this.form.peopleCount',this.estate.trashSinglePrice);

        if(this.form.months > 0 && this.form.peopleCount > 0){
          this.form.trashFee = this.form.peopleCount * this.estate.trashSinglePrice * this.form.months;
          this.form.trashFee = Math.round(this.form.trashFee*100)/100
        }
      },
      /**
       *  计算总价格
       **/
      getAllPrice(){

      },
      sendWxMessage(id){
        console.log('sendWxMessage id',id);
        sendWxMessage(id).then(response => {
          this.msgSuccess("发送成功");
          this.open = false;
        });
      },
      /**
       * 日期选择范围
       **/
      selectDateRange(val){
        console.log('selectDateRange',val);
        var date1 = val[0];
        var year1 = date1.getFullYear();
        var month1 = date1.getMonth() + 1;
        var day1 = date1.getDate();

        var date2 = val[1];
        var year2 = date2.getFullYear();
        var month2 = date2.getMonth() + 1;
        var day2 = date2.getDate();

        this.form.dateRange = [year1+'-'+month1+'-'+day1,year2+'-'+month2+'-'+day2];

        var months = (year2 - year1) * 12 + (month2 - month1) + 1;
        console.log('months',months);

        this.months = months;
        this.form.months = months;
        this.getWyfFee();
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          orderNo: undefined,
          estateId: undefined,
          propertyId: undefined,
          userId: undefined,
          payPlatform:undefined,
          payPlatformId:undefined,
          wyfFee: undefined,
          wyfYhPrice:undefined,
          waterFee: undefined,
          trashFee: undefined,
          trashYouhui:undefined,
          electricFee: undefined,
          wyfSinglePrice:0,
          peopleCount:undefined,
          roomNo:undefined,
          roomType:0,
          roomAreas:undefined,
          phoneNum: undefined,
          beginTime: undefined,
          endTime: undefined,
          state: undefined,
          months:0,
          useIntegral: undefined,
          dkRate:undefined,
          payMoney: undefined,
          totalMoney: undefined,
          createTime: undefined,
          transactionId: undefined,
          outTradeNo: undefined,
          mchId: undefined,
          saveType:0,
          isOpenReceipt:undefined,
          receiptImgUrl:undefined,
          receiptImgUrlPath:undefined,
          carFee:undefined,
          carYouhui:undefined,
          jiaYaFee:undefined,
          jiaYaYouhui:undefined,
          remark:undefined,
          // 日期范围
          dateRange: [],
          dateRangeTime:[new Date(),new Date()],
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        console.log('dateRange',this.dateRange);
        if(this.dateRange !=undefined && this.dateRange.length === 2){
          this.queryParams.beginDate = this.dateRange[0];
          this.queryParams.endDate = this.dateRange[1];
        }
        this.getList();
      },

      selectDelete(num) {
        this.queryParams.pageNum = 1;
        this.queryParams.isDel = num;
        if (this.queryParams.state = 7){
          this.queryParams.state = 4;
        }
        this.getList();
      },

      selectYajinDelete(num) {
        this.queryParams.pageNum = 1;
        this.queryParams.state = num;
        if (this.queryParams.isDel = 1){
          this.queryParams.isDel = 0;
        }
        this.getList();
      },

      handleRefund(row){
        const ids = row.id || this.ids;
        this.$confirm('是否确认执行退款，订单编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.loading = true;
          return refundOrder(row);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.msgSuccess("退款执行成功");
        }).catch(() => {});
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id);
        this.single = selection.length!==1;
        this.multiple = !selection.length;
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加物业费订单";
      },
      downloadSettle(row) {
        window.location.href = process.env.VUE_APP_BASE_API + "/common/download/settle/" + row.id;
      },
      handleOrderPayStatusQuery(row){
        const id = row.id || this.ids;
        queryOrder(id).then(response => {
          this.msgSuccess("查询成功");
          this.getList();
        });
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.loading = true;
        this.reset();
        const id = row.id || this.ids;
        getOrder(id).then(response => {
          this.loading = false;
          this.form = response.data;
          this.estate = this.form.estate;
          this.wxUserOptions = response.data.wxUsers;

          this.queryParamsWxUser.estateId = response.data.estate.id;
          if(this.form.roomType === 0){
            this.form.wyfSinglePrice = response.data.estate.wyfHighSinglePrice;
          } else if(this.form.roomType === 1){
            this.form.wyfSinglePrice = response.data.estate.wyfLowSinglePrice;
          } else if(this.form.roomType === 2){
            this.form.wyfSinglePrice = response.data.estate.wyfBusinessPrice;
          } else if(this.form.roomType === 3){
            this.form.wyfSinglePrice = response.data.estate.wyfVillaSinglePrice;
          }

          if(this.form.beginTime == undefined){
            this.form.dateRangeTime = [new Date(),new Date()]
          }

          this.open = true;
          this.title = "修改物业费订单";
        });
      },
      /** 提交按钮 */
      submitForm(saveType) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.buttonLoading = true;
            // this.form.estateId = this.queryParamsWxUser.estateId;
            // this.form.dateRangeTime = [];
            this.form.saveType = saveType;
            if (this.form.id != null) {
              updateOrder(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }).finally(() => {
                this.buttonLoading = false;
              });
            } else {
              addOrder(this.form).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }).finally(() => {
                this.buttonLoading = false;
              });
            }
          }
        });
      },
      /** 提交按钮 */
      submitFormTime() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.buttonLoading = true;
            updateOrderTime(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.openTime = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除物业费订单编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.loading = true;
          return delOrder(ids);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 作废按钮操作 */
      handleVoid(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除物业费订单编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.loading = true;
          return voidOrder(ids);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
      },

      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有物业费订单数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportOrder(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
      }
    }
  };
</script>
